home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / batchut / strings2.zip / STRINGS.DOC < prev    next >
Text File  |  1992-11-25  |  49KB  |  1,080 lines

  1. STRINGS.COM  (Version 2.0)        Copyright (c) 1991, 1992 Douglas Boling
  2. -------------------------------------------------------------------------
  3.               First Published in PC Magazine December 22, 1992 (Utilities)
  4. -------------------------------------------------------------------------
  5.  
  6. STRINGS:
  7.  
  8.         The original STRINGS.COM removed the restrictions imposed by the DOS
  9. batch file language to give your batch files more versatility. This upgraded
  10. TSR version enhances a number of the original functions and implements more
  11. than 35 new ones.
  12.  
  13.  
  14. Batch Files Get Even Better With Our STRINGS 2.0
  15. BY DOUGLAS BOLING
  16.  
  17.     The new version contains not only the batch file commands of the
  18. original utility, but 6 enhanced functions and 35 new ones as well.
  19. In all, as shown in Figure 1 (below) STRINGS now adds about 70 commands
  20. to the batch file language. (Some of these commands can be used from
  21. the DOS prompt as well.) Where the original STRINGS let you add a series
  22. of numbers, read a line from a file, or ask a user a question,
  23. STRINGS 2.0 includes additional functions that allow batch files to
  24. query the date and time, get the current country and codepage, and even
  25. read and write to memory locations.
  26.  
  27.      Perhaps the outstanding new feature of STRINGS 2.0 is that under
  28. DOS 3.3 or later it can now act as an extension to the DOS command
  29. processor, COMMAND.COM.  This required rewriting the program so it could
  30. become a TSR.
  31.      Once memory resident, since COMMAND.COM no longer has to search,load, and run the program, STRINGS's commands execute with the same speed
  32. as do such internal COMMAND.COM functions as COPY, RENAME, and DELETE.
  33.  
  34.      The new program itself bears the same name, STRINGS.COM, as its
  35. predecessor.  That allows you to upgrade instantly simply by copying the
  36. new program over the old. To avoid confusion, I will refer to the original
  37. version of the utility as STRINGS1. If you have never used STRINGS1,
  38. reading through the original article will be helpful, but I'll try to
  39. explain enough here to make that unnecessary.
  40.  
  41.     To assemble the source you will need an assembler compatible with
  42. Microsoft's MASM 2.0.  The commands to create STRINGS.COM are:
  43.  
  44.                              MASM STRINGS;
  45.                              LINK STRINGS;
  46.                              EXE2BIN STRINGS STRINGS.COM
  47.  
  48.  
  49. USING STRINGS
  50.  
  51.      At first sight, the complete syntax for STRINGS.COM may seem
  52. dauntingly complex:
  53.  
  54.      STRINGS [/?][/M][/Q][/Pc][/Bn][/I][/U] [env var =] FUNCTION [Params]
  55.  
  56. But it's a lot easier to use than it looks.  One reason is that, in
  57. addition to this article, the on-screen help facilities are extensive.
  58. Simply enter STRINGS at the DOS prompt and you'll get an explanation of
  59. every item in the syntax line above. Entering STRINGS /? will give you a
  60. complete list of all the commands denoted by FUNCTION, and
  61.  
  62.                            STRINGS /? FUNCTION
  63.  
  64. will spell out the purpose, usage, and Prams (parameters) of each
  65. individual command.  Note that in both of these last two commands the
  66. /? can be replaced by /HELP.
  67.  
  68.     Many STRINGS commands require no arguments; for these you just enter
  69.  
  70.                            STRINGS FUNCTION
  71.  
  72. For example, to return the last available drive letter you simply enter:
  73.  
  74.  
  75.                            STRINGS LASTDRIVE
  76.  
  77. STRINGS will respond by displaying the last available drive letter on
  78. your system.
  79.  
  80.     For commands that do take input parameters, the arguments are
  81.  separated by commas.  For example, the command LEFT, which returns the
  82. first n characters (including spaces) of a string, has two parameters:
  83. the input string and the number of characters to return.  Thus,
  84.  
  85.  
  86.                            STRINGS LEFT This is a string, 9
  87.  
  88. will return the left nine characters ``This is a".  Note the comma
  89. separating the two parameters in the command line.
  90.  
  91.     The results of any STRINGS command can be assigned to an environmentvariable.  Simply insert the name for the variable and an equals sign
  92. between STRINGS and FUNCTION.  For example, by changing the previous
  93. example to
  94.  
  95.  
  96.                            STRINGS ANSWER =LEFT This is a string, 9
  97.  
  98. STRINGS will assign the string ``This is a'' to the environment variable
  99. ANSWER.
  100.  
  101.     As shown above, STRINGS has seven command line switches:
  102. /M, /Pc, /Q, /Bn, /I, /U and /?.  The switch must be included on the
  103. command line before the environment variable or, if no variable is
  104. specified, before the command.
  105.  
  106.     By default, STRINGS stores variables in the Active environment,
  107. which is created by the current copy of COMMAND.COM.  If the /M switch
  108. is used, however, STRINGS stores variables in the master environment,
  109. which is created by COMMAND.COM when DOS starts.
  110.  
  111.     In Windows, while each DOS box has its own Active environment, all
  112. share the Master environment.  By using the /M switch, variables can be
  113. read by all programs, including those in individual Windows DOS boxes.
  114. The /M switch is also useful when you want to preserve a variable
  115. assignment you make while shelled out from a program, for the local
  116. environment is lost when you exit from DOS back into your application.
  117.  
  118.     Reverting to the previous example, to assign the results to the
  119. environment variable RESULT in the Master environment, the command would
  120. be
  121.  
  122.                    STRINGS /M RESULT = LEFT This is a string, 9
  123.  
  124.     The MASTERVAR command returns the string assigned to a variable inthe Master environment.  For example, the command
  125.  
  126.                           STRINGS MASTERVAR RESULT
  127.  
  128. returns the string assigned to the RESULT environment variable even if
  129. this command is executed in a different DOS box from the one that was
  130. used in previous examples!
  131.  
  132.      The /Pc (or Parse) switch tells STRINGS to use the c character
  133. rather than the comma to separate multiple parameters.  This switch
  134. allows you to work with strings that contain commas.
  135.  
  136.     The /Q (or Quiet) switch, which was added in a maintenance release
  137. of STRINGS 1.0, prevents STRINGS from writing to the screen. This switch
  138. is useful if the STRINGS command may produce an error message that you
  139. don't want displayed on the screen.
  140.  
  141.     New in STRINGS 2.0 is the /Bn switch, which is used to change the number
  142. base that STRINGS uses to interpret numbers. STRINGS defaults to base 10
  143. arithmetic, but by using the /B switch, you can set the base to any number
  144. from 2 to 16.  Thus, while the statement
  145.  
  146.                                          STRINGS ADD 9, 1 
  147.  
  148. returns the standard value 10, the statement
  149.  
  150.                                          STRINGS /B16 ADD 9, 1 
  151.  
  152. returns the ``number'' A, since A in hexadecimal (base 16) is 10 in decimal.
  153. You'll want to use the /B switch working with several of the new STRINGS
  154. commands, where it is more appropriate to use hexadecimal than decimal
  155. numbers.
  156.  
  157.     If your system is running DOS 3.3 or later, using the /I switch installs
  158. STRINGS as a resident extension of COMMAND.COM.  (How STRINGS actuallyaccomplishes this will be discussed later.) Unlike most TSRs, which are
  159. installed at startup, STRINGS works best if it is installed only when
  160. and for as long as needed; it should be removed from memory once the
  161. batch file has completed in order to avoid wasting valuable systemmemory.  To uninstall STRINGS, you simply use the /U switch.
  162.  
  163.     Installing STRINGS as a resident extension does not alter the syntax
  164. of any of its commands. The speed advantage is dramatic. The disadvantage,
  165. however, is that once installed, STRINGS (like all internal COMMAND.COM
  166. commands) cannot return an exit code to COMMAND.COM. This means that
  167. while STRINGS is resident, you can't use the handy IF ERRORLEVEL statement
  168. in .BAT files to test the result of STRINGS commands.
  169.  
  170.     If your batch file requires the error level codes returned by STRINGS,
  171. two solutions are available.  The first and most obvious is simply not
  172. to install STRINGS at the start of the batch file.  When not installed,
  173. STRINGS 2.0 returns the same error codes as STRINGS 1.0.
  174.  
  175.     The second solution is to sp